using DAL = IrisGenerator.Common.DatabaseModel.DataAccess;
using IrisGenerator.Common.DataTypes;
using IrisGenerator.Common.Tools;
using System;
namespace IrisGenerator.Common.DatabaseModel {
    
    
    public partial class Column {
        
        private System.Nullable<System.Guid> _colId;
        
        private System.Nullable<System.Guid> _tabId;
        
        private System.Nullable<System.Guid> _metId;
        
        private string _colName;
        
        private string _colFormatedName;
        
        private System.Nullable<int> _colPrecision;
        
        private string _colLength;
        
        private System.Nullable<bool> _colNullable;
        
        private System.Nullable<bool> _colComputed;
        
        private System.Nullable<bool> _colSequential;
        
        private System.Nullable<int> _colGenerateValue;
        
        private Metatype _metatype;
        
        private Table _table;
        
        private InsertColumnsCollection _insertColumnsCollection;
        
        private OrderbyColumnsCollection _orderbyColumnsCollection;
        
        private RequestParameterCollection _requestParameterCollection;
        
        private SelectColumnsCollection _selectColumnsCollection;
        
        private UpdateColumnsCollection _updateColumnsCollection;
        
        public virtual System.Nullable<System.Guid> ColId {
            get {
                return _colId;
            }
            set {
                _colId = value;
            }
        }
        
        public virtual string ColName {
            get {
                return _colName;
            }
            set {
                _colName = value;
            }
        }
        
        public virtual string ColFormatedName {
            get {
                return _colFormatedName;
            }
            set {
                _colFormatedName = value;
            }
        }
        
        public virtual System.Nullable<int> ColPrecision {
            get {
                return _colPrecision;
            }
            set {
                _colPrecision = value;
            }
        }
        
        public virtual string ColLength {
            get {
                return _colLength;
            }
            set {
                _colLength = value;
            }
        }
        
        public virtual System.Nullable<bool> ColNullable {
            get {
                return _colNullable;
            }
            set {
                _colNullable = value;
            }
        }
        
        public virtual System.Nullable<bool> ColComputed {
            get {
                return _colComputed;
            }
            set {
                _colComputed = value;
            }
        }
        
        public virtual System.Nullable<bool> ColSequential {
            get {
                return _colSequential;
            }
            set {
                _colSequential = value;
            }
        }
        
        public virtual System.Nullable<int> ColGenerateValue {
            get {
                return _colGenerateValue;
            }
            set {
                _colGenerateValue = value;
            }
        }
        
        public virtual Metatype Metatype {
            get {
                if ((this._metatype == null)) {
                    this._metatype = Metatype.Load(this._metId);
                }
                return this._metatype;
            }
            set {
                _metatype = value;
            }
        }
        
        public virtual Table Table {
            get {
                if ((this._table == null)) {
                    this._table = IrisGenerator.Common.DatabaseModel.Table.Load(this._tabId);
                }
                return this._table;
            }
            set {
                _table = value;
            }
        }
        
        public virtual InsertColumnsCollection InsertColumnsCollection {
            get {
                if ((this._insertColumnsCollection == null)) {
                    _insertColumnsCollection = IrisGenerator.Common.DatabaseModel.InsertColumns.Select_INSERT_COLUMNS_By_COL_ID(this.ColId);
                }
                return this._insertColumnsCollection;
            }
        }
        
        public virtual OrderbyColumnsCollection OrderbyColumnsCollection {
            get {
                if ((this._orderbyColumnsCollection == null)) {
                    _orderbyColumnsCollection = IrisGenerator.Common.DatabaseModel.OrderbyColumns.Select_ORDERBY_COLUMNS_By_COL_ID(this.ColId);
                }
                return this._orderbyColumnsCollection;
            }
        }
        
        public virtual RequestParameterCollection RequestParameterCollection {
            get {
                if ((this._requestParameterCollection == null)) {
                    _requestParameterCollection = IrisGenerator.Common.DatabaseModel.RequestParameter.Select_REQUEST_PARAMETER_By_COL_ID(this.ColId);
                }
                return this._requestParameterCollection;
            }
        }
        
        public virtual SelectColumnsCollection SelectColumnsCollection {
            get {
                if ((this._selectColumnsCollection == null)) {
                    _selectColumnsCollection = IrisGenerator.Common.DatabaseModel.SelectColumns.Select_SELECT_COLUMNS_By_COL_ID(this.ColId);
                }
                return this._selectColumnsCollection;
            }
        }
        
        public virtual UpdateColumnsCollection UpdateColumnsCollection {
            get {
                if ((this._updateColumnsCollection == null)) {
                    _updateColumnsCollection = IrisGenerator.Common.DatabaseModel.UpdateColumns.Select_UPDATE_COLUMNS_By_COL_ID(this.ColId);
                }
                return this._updateColumnsCollection;
            }
        }
        
        private void Clean() {
            this.ColId = null;
            this._tabId = null;
            this._metId = null;
            this.ColName = string.Empty;
            this.ColFormatedName = string.Empty;
            this.ColPrecision = null;
            this.ColLength = string.Empty;
            this.ColNullable = null;
            this.ColComputed = null;
            this.ColSequential = null;
            this.ColGenerateValue = null;
            this.Metatype = null;
            this.Table = null;
            this._insertColumnsCollection = null;
            this._orderbyColumnsCollection = null;
            this._requestParameterCollection = null;
            this._selectColumnsCollection = null;
            this._updateColumnsCollection = null;
        }
        
        private void Fill(System.Data.DataRow dr) {
            this.Clean();
            if ((dr["COL_ID"] != System.DBNull.Value)) {
                this.ColId = ((System.Nullable<System.Guid>)(dr["COL_ID"]));
            }
            if ((dr["TAB_ID"] != System.DBNull.Value)) {
                this._tabId = ((System.Nullable<System.Guid>)(dr["TAB_ID"]));
            }
            if ((dr["MET_ID"] != System.DBNull.Value)) {
                this._metId = ((System.Nullable<System.Guid>)(dr["MET_ID"]));
            }
            if ((dr["COL_NAME"] != System.DBNull.Value)) {
                this.ColName = ((string)(dr["COL_NAME"]));
            }
            if ((dr["COL_FORMATED_NAME"] != System.DBNull.Value)) {
                this.ColFormatedName = ((string)(dr["COL_FORMATED_NAME"]));
            }
            if ((dr["COL_PRECISION"] != System.DBNull.Value)) {
                this.ColPrecision = ((System.Nullable<int>)(dr["COL_PRECISION"]));
            }
            if ((dr["COL_LENGTH"] != System.DBNull.Value)) {
                this.ColLength = ((string)(dr["COL_LENGTH"]));
            }
            if ((dr["COL_NULLABLE"] != System.DBNull.Value)) {
                this.ColNullable = ((System.Nullable<bool>)(dr["COL_NULLABLE"]));
            }
            if ((dr["COL_COMPUTED"] != System.DBNull.Value)) {
                this.ColComputed = ((System.Nullable<bool>)(dr["COL_COMPUTED"]));
            }
            if ((dr["COL_SEQUENTIAL"] != System.DBNull.Value)) {
                this.ColSequential = ((System.Nullable<bool>)(dr["COL_SEQUENTIAL"]));
            }
            if ((dr["COL_GENERATE_VALUE"] != System.DBNull.Value)) {
                this.ColGenerateValue = ((System.Nullable<int>)(dr["COL_GENERATE_VALUE"]));
            }
        }
        
        public static ColumnCollection Select_COLUMN_By_MET_ID(System.Nullable<System.Guid> MET_ID) {
            DAL.Column dbo = null;
            try {
                dbo = new DAL.Column();
                System.Data.DataSet ds = dbo.Select_COLUMN_By_MET_ID(MET_ID);
                ColumnCollection collection = new ColumnCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Column obj = new Column();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static ColumnCollection Select_COLUMN_By_TAB_ID(System.Nullable<System.Guid> TAB_ID) {
            DAL.Column dbo = null;
            try {
                dbo = new DAL.Column();
                System.Data.DataSet ds = dbo.Select_COLUMN_By_TAB_ID(TAB_ID);
                ColumnCollection collection = new ColumnCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Column obj = new Column();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static ColumnCollection GetAll() {
            DAL.Column dbo = null;
            try {
                dbo = new DAL.Column();
                System.Data.DataSet ds = dbo.COLUMN_Select_All();
                ColumnCollection collection = new ColumnCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Column obj = new Column();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static Column Load(System.Nullable<System.Guid> COL_ID) {
            DAL.Column dbo = null;
            try {
                dbo = new DAL.Column();
                System.Data.DataSet ds = dbo.COLUMN_Select_One(COL_ID);
                Column obj = null;
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        obj = new Column();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Load() {
            DAL.Column dbo = null;
            try {
                dbo = new DAL.Column();
                System.Data.DataSet ds = dbo.COLUMN_Select_One(this.ColId);
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Insert() {
            DAL.Column dbo = null;
            try {

                dbo = new DAL.Column();
                this.ColId=dbo.COLUMN_Insert(this.Table.TabId, this.Metatype.MetId, this.ColName, this.ColFormatedName, this.ColPrecision, this.ColLength, this.ColNullable, this.ColComputed, this.ColSequential, this.ColGenerateValue);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Delete() {
            DAL.Column dbo = null;
            try {
                dbo = new DAL.Column();
                dbo.COLUMN_Delete(this.ColId);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Update() {
            DAL.Column dbo = null;
            try {
                dbo = new DAL.Column();
                dbo.COLUMN_Update(this.ColId, this._tabId, this._metId, this.ColName, this.ColFormatedName, this.ColPrecision, this.ColLength, this.ColNullable, this.ColComputed, this.ColSequential, this.ColGenerateValue);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
    }
}
